package com.zixi.beverage_order.controller.customer;

import com.zixi.beverage_order.mapper.ReviewMapper;
import com.zixi.beverage_order.pojo.*;
import com.zixi.beverage_order.service.customer.WxOrderListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/get")
@ResponseBody
public class WxOrderListController {
//    用户已经创建了订单后进行购物车里的东西修改删除的控制类
    @Autowired
    WxOrderListService wxOrderListService;

    @Autowired
    ReviewMapper reviewMapper;

    @PostMapping("/orderlist")
//    用户填写好了本订单信息后发送到后台获取订单号的请求
    public ReturnOrderList wxGetOrderListInfo(@RequestBody OrderList orderList) {
        return wxOrderListService.newOrderList(orderList);
    }

    @PostMapping("/shoppingtrolley")
//    用户已经有了购物车订单获取购物车产品的请求
    public ShoppingTrolley wxGetshoppingtrolley(@RequestBody OrderList orderList){
        return wxOrderListService.wxGetshoppingtrolley(orderList);
    }

    @PostMapping("/unfinishedlist")
//    获取未完成的订单（没有finishtime）
    public List<ReturnOrderList> getUnfinishedList(@RequestBody Customer customer){
        return wxOrderListService.getUnfinishedList(customer);
    }
    @PostMapping("/finishedlist")
//    获取已经完订单（有finishtime）
    public List<ReturnOrderList> getFinishedList(@RequestBody Customer customer){
        return wxOrderListService.getFinishedList(customer);
    }
    @PostMapping("/getlistinfo")
    //获取所选订单的信息 包括是什么奶茶
    public ShoppingTrolley getListInfo(@RequestBody OrderList orderList){
        return wxOrderListService.getListInfo(orderList);
    }
    @PostMapping("/getonereview")
    public Review getOneReview(@RequestBody Review review){
        System.out.println(review);
        Map<String,Object> map = new HashMap<>();
        map.put("order_list_id",review.getOrderListId());
        List<Review> reviewList = reviewMapper.selectByMap(map);
        return reviewList.isEmpty()?review:reviewList.get(0);
    }
    @PostMapping("/setonereview")
    public Review setOneReview(@RequestBody Review review){
        reviewMapper.insert(review);
        System.out.println(review);
        return null;
    }
}

